import { MaterialModel } from '~/model/MaterialModel'

export abstract class MaterialSerializer {
  static serialize(model: MaterialModel): SentData {
    return {
      name: model.name,
      // alias: model.alias,
      unit: model.unit,
      unitPrice: model.unitPrice,
      specification: model.specification,
      comment: model.comment,
      taken_off: model.takenOff,
      group: model.group,
    }
  }

  static deserialize(data: ReceivedData): MaterialModel {
    const model = new MaterialModel()
    model.id = data.id
    model.name = data.name
    // model.alias = data.alias
    model.unit = data.unit
    model.unitPrice = data.unitPrice

    model.specification = data.specification
    model.comment = data.comment
    model.takenOff = data.taken_off
    model.group = data.group
    return model
  }
}

interface SentData {
  name: string
  // alias: string
  unit: string
  unitPrice: number

  specification: string
  comment: string
  taken_off: boolean
  group: string
}

interface ReceivedData {
  id: number
  name: string
  // alias: string
  unit: string
  unitPrice: number

  specification: string
  comment: string
  taken_off: boolean
  group: string
}
